package com.demo.intentdemo;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

public class FirstActivity extends AppCompatActivity {

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestPermissions(new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.SEND_SMS}, 101);
        setContentView(R.layout.activity_first);
        Button btnSecond = findViewById(R.id.button1);
        btnSecond.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
//				ComponentName comp=new ComponentName(FirstActivity.this, SecondActivity.class);
//				Intent intent=new Intent();
//				intent.setComponent(comp);
//				FirstActivity.this.startActivity(intent);

                Intent intent = new Intent();
                intent.setClass(FirstActivity.this, SecondActivity.class);
//                Intent intent=new Intent(FirstActivity.this, SecondActivity.class);
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnEat = findViewById(R.id.button_eat);
        btnEat.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.setAction("action.EAT");
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnSleep = findViewById(R.id.button_sleep);
        btnSleep.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.setAction("action.SLEEP");
                FirstActivity.this.startActivity(intent);
            }
        });
        Button btnHome = findViewById(R.id.button_home);
        btnHome.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnDial = findViewById(R.id.button_dial);
        btnDial.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel://10086"));
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnCall = findViewById(R.id.button_call);
        btnCall.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:10086"));
//				intent.setAction(Intent.ACTION_CALL);
//				intent.setData(Uri.parse("tel:10086"));
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnContacts = findViewById(R.id.button_Contacts);
        btnContacts.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 0);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/2"));
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnWeb = findViewById(R.id.button_web);
        btnWeb.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.zzu.edu.cn"));
                FirstActivity.this.startActivity(intent);
            }
        });

        Button btnSms = findViewById(R.id.button_sms);
        btnSms.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                //requestPermissions(new String);
                Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto://10086"));
                intent.putExtra("sms_body", "我要查话费");
                FirstActivity.this.startActivity(intent);
            }
        });
//
    }
}

